package com.joyrec.util.db.redis

trait RedisQueue {

}

trait MsgTypeRedisQueue extends RedisQueue {
  type MsgType
  protected val queueName: MsgType
  def push(msg: MsgType)
  def poll: Option[MsgType]

  def size: Long

  def hasMsg: Boolean = size > 0

}



trait BytesSingleRedisQueue extends MsgTypeRedisQueue {
  type MsgType = Array[Byte]
  protected val redis: SingleRedisTpl
  def push(msg: Array[Byte]) =
    redis.run { r =>
      r.rpush(queueName, msg)
    }
  def poll = redis.run { r =>
    Option(r.lpop(queueName))
  }
  def size = redis.run {
    _.llen(queueName)
  }
}